<%@ page contentType="text/html;charset=UTF-8"%>
<%@ include file="/common/taglibs.jsp"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta name="nav" content="0" />
<meta name="acc" content="plan-1" />
<title>编制监督计划</title>
<script type="text/javascript"
	src="<c:url value='/ext/ui/jquery-ui-1.8.12.custom.min.js'/>"></script>
<link href="${ctx}/styles/lightness/jquery-ui-1.8.12.custom.css"
	rel="stylesheet" />
<script type="text/javascript" charset="utf-8"
	src="<c:url value='/KindEditor/kindeditor.js'/>"></script>
<script type="text/javascript">
	$(document).ready(
			function() {
				$("#superviserCode").focus();
				$("#inputForm").validate({
					event : "blur",
					isTip : true,
					rules : {
						superviserCode:{
							required:true,
							remote : "${ctx}/quality/plan!checkSuperviserCode.action?oldSuperviserCode="
								+ encodeURIComponent('${superviserCode}')
						}
					},
					messages : {
						superviserCode:{
							remote:"<font color='red'>监督编号已存在</font>"
						}
					}
				});

				$("#process").click(
						function() {
							if (isProcess()) {
								$("#inputForm").attr("action",
										"${ctx}/quality/plan!start.action");
								KE.sync("content");
								$("#inputForm").submit();
							}
						});
			});

	var i = 1;
	function addFile(divName, fileName) {
		var dv = document.getElementById(divName);

		var file = document.createElement("input");
		file.type = "file";
		file.name = fileName;
		file.id = fileName + i;
		dv.appendChild(file);

		var btn = document.createElement("input");
		btn.type = "button";
		btn.id = btn.name = "btn" + i;
		btn.value = "删除";

		btn.onclick = function() {
			var b = document.getElementById(btn.id);
			dv.removeChild(b.nextSibling);
			dv.removeChild(b.previousSibling);
			dv.removeChild(b);
		}

		dv.appendChild(btn);
		dv.appendChild(document.createElement("BR"));

		i++;
	}
	
	KE.show({
		id : 'content',
		cssPath : './index.css',
		afterCreate : function(id) {
			KE.event.ctrl(document, 13, function() {
				KE.sync(id);
				document.forms['inputForm'].submit();
			});
			KE.event.ctrl(KE.g[id].iframeDoc, 13, function() {
				KE.sync(id);
				document.forms['inputForm'].submit();
			});
		}
	});
</script>
</head>
<body>
	<form action="${ctx }/quality/plan!save.action" method="post"
		id="inputForm" class="yform" enctype="multipart/form-data">
		<div id="caption">
			<h6>编制监督计划</h6>
		</div>
		<input type="hidden" id="id" name="id" value="${id }"> <input
			type="hidden" id="projectId" name="projectId"
			value="${empty param.projectId ? projectId : param.projectId}">
		<div>
			<table class="noborder">
				<tr class="type-text">
					<td>项目名称</td>
					<td><pt:labels type="proj"
							argument1="${empty param.projectId ? projectId : param.projectId}"
							single="true"></pt:labels></td>
				</tr>
				<tr class="type-text">
					<td>监督编号</td>
					<td><input type="text" id="superviserCode"
						name="superviserCode" value="${superviserCode }" class="required">
					</td>
				</tr>
				<tr class="type-text">
					<td>监督计划内容</td>
					<td><textarea name="content" id="content" class="required">${content }</textarea>
					</td>
				</tr>
				<tr class="type-text">
					<td>备注</td>
					<td><textarea name="remark" id="remark">${remark }</textarea>
					</td>
				</tr>
				<tr class="type-text">
					<td><input type="button" value="添加上传"
						onclick="addFile('sources','upload')"></td>
					<td colspan="3" id="sources"></td>
				</tr>
			</table>
			<c:if test="${not empty attachmentSet }">
				<div id="caption">
					<h6>${licenseplateNumber}已有附件</h6>
				</div>
				<table>
					<c:forEach items="${attachmentSet }" var="attachment"
						varStatus="state">
						<tr id="tr${state.index }">
							<td colspan="4"><a title="下载"
								href="${ctx}/servlet/annex?id=${attachment.id}">${attachment.upfileFileName}(${attachment.type})<fmt:formatDate
										value="${attachment.fileTime}" pattern="yyyy-MM-dd" /> </a> <span
								onclick="deleteAttachmentById('${attachment.id}','tr${state.index }')"
								class="delete" title="删除附件"></span></td>
						</tr>
					</c:forEach>
				</table>
			</c:if>
		</div>
		<div class="type-button">
			<input type="submit" class="submit" value="暂存" />&nbsp;
			<c:if test="${status == '01' || status == null}">
				<input type="button" class="submit" value="提交" id="process" />&nbsp;</c:if>
			<input type="button" value="返回" class="reset"
				onclick="history.back()" />
		</div>
	</form>
</body>
</html>